<template>
	<div class="right-cps-view" v-loading="loading">
		<div class="tbs-view">
			<el-button :type="newTab2FLg == 1 ? 'primary' : ''" @click="newTab2FLg = 1">{{
				$t("message.bgDataStyle.title")
			}}</el-button>
			<el-button :type="newTab2FLg == 2 ? 'primary' : ''" @click="newTab2FLg = 2">{{
				$t("message.bgDataStyle.title2") }}</el-button>
			<!-- -弹框是否出现-{{ rightViewFlag1 }}--
			-是否修改-{{ DataChange }}-- -->
		</div>

		<!-- content -->

		<div class="add-view" v-show="$hasEditPermission('/BHView')">
			<el-button size="small" @click="newAdd = true, changType()"
				:style="{ background: type == 1 ? '#bc000f' : '', color: type == 1 ? 'white' : '', borderColor: type == 1 ? '#bc000f' : '' }"
				:disabled="delFlg" v-show="newTab2FLg == 1">
				{{ $t("message.bhView.topBtnDownList.addition") }}
			</el-button>
			<el-button size="small" type="default" :disabled="(type == 1 || noDataFlg)" @click="DelOperationApi"
				:style="{ background: delFlg ? '#bc000f' : '', color: delFlg ? 'white' : '', borderColor: delFlg ? '#bc000f' : '' }"
				v-show="newTab2FLg == 1">
				{{ $t("message.bhView.topBtnDownList.delete") }}
			</el-button>
		</div>

		<div style="padding:10px;">
			<div class="list">
				<ux-grid ref="multipleTable" :data="allList" :header-cell-style="{
					color: 'rgba(0, 0, 0)',
					fontSize: '14px',
					textAlign: 'center',
					fontWeight: '700',
					padding: 0,
					height: '32px',
				}" :cell-style="{
					color: 'rgba(96,98,102,1)',
					fontSize: '14px',
					textAlign: 'center',
					padding: 0,
					height: '32px',
				}" :row-style="{
					color: 'rgba(96,98,102,1)',
					fontSize: '13px',
					textAlign: 'left',
					padding: 0,
					height: '32px',
				}" @current-change="handleSelectionChange" height="185">
					<template slot="empty"> No data </template>
					<ux-table-column width="40" type="index">
						<template slot-scope="scope">
							<p style="text-align:center;">{{ scope.row.id + 1 }}</p>
						</template>
					</ux-table-column>

					<ux-table-column :title="$t('message.bgDataStyle.table.column1')" width="125">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.wCodName" placement="top-start">
								<p>{{ scope.row.wCodName }}</p>
							</el-tooltip>
						</template>
					</ux-table-column>

					<ux-table-column :title="$t('message.bgDataStyle.table.column2')" width="60">
						<template slot-scope="scope">
							<p>{{ scope.row.wCodSymb }}</p>
						</template>
					</ux-table-column>

					<ux-table-column :title="$t('message.bgDataStyle.table.column3')" width="70">
						<template slot-scope="scope">
							<p>{{ scope.row.lvl }}</p>
						</template>
					</ux-table-column>

					<ux-table-column :title="$t('message.bgDataStyle.table.column4')" width="100">
						<template slot-scope="scope">
							<p>{{ scope.row.stdDate }}</p>
						</template>
					</ux-table-column>

					<ux-table-column :title="$t('message.bgDataStyle.table.column5')" width="61">
						<template slot-scope="scope">
							<p>{{ scope.row.cyc }}</p>
						</template>
					</ux-table-column>


					<ux-table-column :title="$t('message.bgDataStyle.table.column6')" width="110">
						<template slot-scope="scope">
							<p>{{ scope.row.lstSsnDate }}</p>
						</template>
					</ux-table-column>
					<ux-table-column :title="$t('message.bgDataStyle.table.column7')" width="110">
						<template slot-scope="scope">
							<p>{{ scope.row.nxtSsnDate }}</p>
						</template>
					</ux-table-column>
				</ux-grid>
			</div>
		</div>
		<div class="add-view1" v-show="$hasEditPermission('/BHView') && newTab2FLg == 2">
			<span>
				{{ $t("message.bgDataStyle.label_12") }}
			</span>
			<div>
				<el-button size="small" @click="addEditTableFn">
					{{ $t("message.bhView.topBtnDownList.addition") }}
				</el-button>
				<el-button size="small" type="default" @click="delEditTableFn">
					{{ $t("message.bhView.topBtnDownList.delete") }}
				</el-button>
			</div>
		</div>

		<div :class="$hasEditPermission('/BHView') ? '' : 'maskDisabled1'" style="padding:10px;" v-show="newTab2FLg == 2">
			<div class="list editTable">
				<ux-grid :class="$hasEditPermission('/BHView') ? '' : 'maskDisabled2'" ref="multipleTable1" :data="tableList" :header-cell-style="{
					color: 'rgba(0, 0, 0)',
					fontSize: '14px',
					textAlign: 'center',
					fontWeight: '700',
					padding: 0,
					height: '32px',
				}" :cell-style="{
					color: 'rgba(96,98,102,1)',
					fontSize: '14px',
					textAlign: 'center',
					padding: 0,
					height: '32px',
				}" :row-style="{
					color: 'rgba(96,98,102,1)',
					fontSize: '13px',
					textAlign: 'left',
					padding: 0,
					height: '32px',
				}" @current-change="handleSelectionChange1" height="185">
					<template slot="empty"> No data </template>
					<ux-table-column width="50">
						<template slot-scope="scope">
							<p style="text-align:center;">{{ scope.row.partsNo }}</p>
						</template>
					</ux-table-column>

					<ux-table-column :title="$t('message.bgDataStyle.table.column8')" width="95">
						<template slot-scope="scope">
							<el-input class="left" v-model="scope.row.partsName"
								@input="scope.row.partsName = $setMaxLength(scope.row.partsName, 30)"></el-input>
						</template>
					</ux-table-column>

					<ux-table-column :title="$t('message.bgDataStyle.table.column9')" width="80">
						<template slot-scope="scope">
							<el-input class="left" v-model="scope.row.partsBui"
								@input="scope.row.partsBui = $setMaxLength(scope.row.partsBui, 10)"></el-input>
						</template>
					</ux-table-column>

					<ux-table-column :title="$t('message.bgDataStyle.table.column10')" width="95">
						<template slot-scope="scope">
							<el-input class="left" v-model="scope.row.partsSize"
								@input="scope.row.partsSize = $setMaxLength(scope.row.partsSize, 30)"></el-input>
						</template>
					</ux-table-column>

					<ux-table-column :title="$t('message.bgDataStyle.table.column11')" width="80">
						<template slot-scope="scope">
							<el-input class="right" v-model="scope.row.partsVol"
								@input="scope.row.partsVol = $setMyNum(scope.row.partsVol, '5 - 1')"></el-input>
						</template>
					</ux-table-column>

					<ux-table-column :title="$t('message.bgDataStyle.table.column12')" width="80">
						<template slot-scope="scope">
							<el-input class="left" v-model="scope.row.partsStan"
								@input="scope.row.partsStan = $setMaxLength(scope.row.partsStan, 30)"></el-input>
						</template>
					</ux-table-column>
					<ux-table-column :title="$t('message.bgDataStyle.table.column13')" width="95">
						<template slot-scope="scope">
							<el-input class="left" v-model="scope.row.partsMate"
								@input="scope.row.partsMate = $setMaxLength(scope.row.partsMate, 30)"></el-input>
						</template>
					</ux-table-column>
					<ux-table-column :title="$t('message.bgDataStyle.table.column14')" width="100">
						<template slot-scope="scope">
							<el-input class="left" v-model="scope.row.partsNote"
								@input="scope.row.partsNote = $setMaxLength(scope.row.partsNote, 40)"></el-input>
						</template>
					</ux-table-column>
				</ux-grid>
			</div>
		</div>


		<div v-show="newTab2FLg == 1"
			:class="[type != 1 && noDataFlg ? 'maskDisabled1' : '', $hasEditPermission('/BHView') ? '' : 'maskDisabled1']"
			class="container">
			<div
				:class="[type != 1 && noDataFlg ? 'maskDisabled2' : '', $hasEditPermission('/BHView') ? '' : 'maskDisabled2']">

				<div class="row spb">
					<div class="item">
						<div class="label">
							{{ $t('message.bgDataStyle.label_1') }}
						</div>
						<el-select v-model="handRow.wCodName" class="ipt orange" placeholder=" ">
							<el-option v-for="item in selectList.wrkClsList" :key="item.key" :label="item.label"
								:value="item.label">
							</el-option>
						</el-select>
					</div>
					<div class="item">
						<div class="label">
							{{ $t('message.bgDataStyle.label_2') }}
						</div>
						<el-input type="text" placeholder=" " v-model="handRow.lvl" class="orange center ipt w47"
							@input="handRow.lvl = $setMaxLength(handRow.lvl, 2)">
						</el-input>
					</div>
				</div>


				<div class="row b700" style="border-top:1px solid #D9D9D9;padding-top: 8px;">
					<div class="item item long-item" style="width: 100%;">
						<div class="label" style="min-width: 160px;">
							周期設定基準
						</div>
						<div class="radio-view" style="width: 490px;justify-content: flex-start;padding-left: 24px;">
							<el-radio v-model="handRow.ctdMode" label="0">設定値</el-radio>
							<el-radio v-model="handRow.ctdMode" label="1">最終検査</el-radio>
						</div>
					</div>
				</div>
				<div class="row" style="min-height: 44px;padding-top: 0;">
					<div class=" item item long-item" style="width: 100%;">
						<div class="label" style="min-width: 160px;"></div>
						<div class=""
							style="width: 490px;display: flex;align-items: center; justify-content: flex-start;">
							<span>点検周期</span>
							<el-input v-model="handRow.cyc" class="small-ipt center  mini-ipt74 orange"
								style="margin: 0 8px;"
								@input="handRow.cyc = $setMyNum(handRow.cyc, '3 - 0')"></el-input>
							<span>ヶ月</span>
						</div>
					</div>
				</div>
				<div class="row" style="min-height: 44px;padding-top: 0;">
					<div class="item item long-item" style="width: 100%;" v-show="handRow.ctdMode == 0">
						<div class="label" style="min-width: 160px;"></div>
						<div class=""
							style="width: 490px;display: flex;align-items: center; justify-content: flex-start;">
							<span>基準年月</span>
							<el-date-picker v-model="handRow.stdDate" class="ipt1 orange" placeholder=" " type="month"
								:clearable="false" :format="timeFormat" :value-format="timeFormat">
							</el-date-picker>
							<el-checkbox v-model="stdJudgeCheck">{{
								$t('message.bgDataStyle.label_6') }}
							</el-checkbox>
						</div>
					</div>
				</div>


				<div class="row spb p-top12" style="border-top:1px solid #D9D9D9">
					<div class="item">
						<div class="label">
							{{ $t('message.bgDataStyle.label_9') }}
						</div>
						<el-select v-model="handRow.lCodName" class="ipt" placeholder=" ">
							<el-option v-for="item in selectList.clnClsList" :key="item.key" :label="item.label"
								:value="item.label">
							</el-option>
						</el-select>
					</div>
					<div class="item">
						<div class="label">
							{{ $t('message.bgDataStyle.label_10') }}
						</div>
						<el-select v-model="handRow.iCodName" class="ipt" placeholder=" ">
							<!-- icdWrkList -->
							<el-option v-for="item in selectList.icdWrkList" :key="item.key" :label="item.label"
								:value="item.label">
							</el-option>
						</el-select>
					</div>
				</div>

				<div class="row spb">
					<!-- <div class="item"> -->
					<div class="label">
						{{ $t('message.bgDataStyle.label_11') }}
					</div>

					<!-- </div> -->
					<el-input v-model="handRow.cWrkCts3" class="ipt long-ipt"
						@input="handRow.cWrkCts3 = $setMaxLength(handRow.cWrkCts3, 800)"></el-input>
				</div>

				<div class="row spb alits p-top12" style="border-top:1px solid #D9D9D9">
					<!-- <div class="item long-item"> -->
					<div class="label">
						{{ $t("message.rightMessage.tab1.label_13") }}
					</div>
					<el-input type="textarea" :rows="4" placeholder=" " v-model="handRow.cWrkCts1"
						@input="handRow.cWrkCts1 = $setMaxLength(handRow.cWrkCts1, 800)"
						class="textarea long-ipt"></el-input>
					<!-- </div> -->
				</div>
				<div class="row spb alits">
					<!-- <div class="item long-item"> -->
					<div class="label">
						{{ $t("message.rightMessage.tab1.label_14") }}
					</div>
					<el-input type="textarea" :rows="4" placeholder=" " v-model="handRow.cWrkCts2"
						@input="handRow.cWrkCts2 = $setMaxLength(handRow.cWrkCts2, 800)"
						class="textarea long-ipt"></el-input>
					<!-- </div> -->
				</div>
				<div class="row spb alits">
					<!-- <div class="item long-item"> -->
					<div class="label">
						{{ $t("message.rightMessage.tab1.label_15") }}
					</div>
					<el-input type="textarea" :rows="4" placeholder=" " v-model="handRow.cIspCts1"
						@input="handRow.cIspCts1 = $setMaxLength(handRow.cIspCts1, 800)"
						class="textarea long-ipt"></el-input>
					<!-- </div> -->
				</div>
			</div>
		</div>

		<!-- footer -->
		<footer class="footer-view">
			<el-button type="primary" v-show="$hasEditPermission('/BHView')" :disabled="!handRow.wCodName" @click="saveRoEditor(true)">{{
				$t("message.bgDataStyle.btn_save")
			}}</el-button>
			<el-button type="warning" @click="onCloseClick">
				{{ $t("message.public.close") }}
			</el-button>
		</footer>
	</div>
</template>

<script>
import { GetOperationList, GetExchangeParts, getOfferCombox, GetSaveMsg, getRequiredMsgByLabel, AddOperation, AddOperationBefor, DelOperation } from "@/api/api";
import { getLocalStorage } from "@/utils/storage";
import eventBus from "@/eventBus/bus";
import { getCookie } from "@/utils/cookie";
import tools from "@/utils/tools.js";
import BASE from '@/utils/base'
import _ from 'lodash-es';
import { showLoading, hideLoading } from "@/utils/loading";

export default {
	name: "TabsCompontens1",
	props: ["tableSelectRow", "rightViewFlag1"],
	data() {
		return {
			//  数据是否修改过
			DataChange: false,
			isConfirming: false,
			newAdd: false,

			newTab2FLg: 1,
			delFlg: false,
			noDataFlg: false,
			userData: getLocalStorage('userData'),
			pickerOptions: {
				disabledDate(time) {
					return time.getTime() > Date.parse('2099-12') || time.getTime() < Date.parse('1900-1');
				}
			},
			loading: false,
			timeFormat: "yyyy-MM",


			checked: false,
			GSData: [
				{
					list1: "11",
					list2: "全開放",
					list3: "22",
					list4: "2022-2",
					list5: "22",
					list6: "22",
					list7: "22",
					list8: "2022-6",
				}, {
					list1: "11",
					list2: "全開放",
					list3: "22",
					list4: "2022-2",
					list5: "22",
					list6: "22",
					list7: "22",
					list8: "2022-6",
				}, {
					list1: "11",
					list2: "全開放",
					list3: "22",
					list4: "2022-2",
					list5: "22",
					list6: "22",
					list7: "22",
					list8: "2022-6",
				}, {
					list1: "11",
					list2: "全開放",
					list3: "22",
					list4: "2022-2",
					list5: "22",
					list6: "22",
					list7: "22",
					list8: "2022-6",
				}, {
					list1: "11",
					list2: "全開放",
					list3: "22",
					list4: "2022-2",
					list5: "22",
					list6: "22",
					list7: "22",
					list8: "2022-6",
				}, {
					list1: "11",
					list2: "全開放",
					list3: "22",
					list4: "2022-2",
					list5: "22",
					list6: "22",
					list7: "22",
					list8: "2022-6",
				}, {
					list1: "11",
					list2: "全開放",
					list3: "22",
					list4: "2022-2",
					list5: "22",
					list6: "22",
					list7: "22",
					list8: "2022-6",
				}, {
					list1: "11",
					list2: "全開放",
					list3: "22",
					list4: "2022-2",
					list5: "22",
					list6: "22",
					list7: "22",
					list8: "2022-6",
				}, {
					list1: "11",
					list2: "全開放",
					list3: "22",
					list4: "2022-2",
					list5: "22",
					list6: "22",
					list7: "22",
					list8: "2022-6",
				}, {
					list1: "11",
					list2: "全開放",
					list3: "22",
					list4: "2022-2",
					list5: "22",
					list6: "22",
					list7: "22",
					list8: "2022-6",
				}, {
					list1: "11",
					list2: "全開放",
					list3: "22",
					list4: "2022-2",
					list5: "22",
					list6: "22",
					list7: "22",
					list8: "2022-6",
				}, {
					list1: "11",
					list2: "全開放",
					list3: "22",
					list4: "2022-2",
					list5: "22",
					list6: "22",
					list7: "22",
					list8: "2022-6",
				}, {
					list1: "11",
					list2: "全開放",
					list3: "22",
					list4: "2022-2",
					list5: "22",
					list6: "22",
					list7: "22",
					list8: "2022-6",
				}
			],
			wrkClsListData: [
				{
					key: 9,
					label: "Ｍ／Ｈ開放"
				}, {
					key: 10,
					label: "開放"
				}, {
					key: 11,
					label: "359"
				},
			],


			allList: [],
			tableList: [],

			tableListRow: {},
			startData: [],
			tableListStartClone: [],
			handRow: {
				wCodName: ""
			},
			selectList: {},

			stdJudgeCheck: false,
			baseYM: "",
			tipMsg: '',
			activeRowIndex: 0,
			isDisable: false,

			oldWCode: 0,
			type: 2,
		};
	},
	components: {
	},
	computed: {
		macNamebValue() {
			return this.$store.state.macNameb;
		},
	},
	watch: {
		macNamebValue: {
			deep: true,
			handler: function (newV, oldV) {
				this.type = 2;
				this.delFlg = false;
				this.handRow = {};
			},
		},
		handRow: {
			deep: true,
			immediate: true,
			handler: function (newV, oldV) {
				setTimeout(() => {
					if (newV.ctdMode == 1) {
						// this.handRow.stdDate = ''
					}
					if (newV.wCodName == '') {
						this.isDisable = true;
					} else {
						this.isDisable = false;
					}

					this.DataChange = !_.isEqual(newV, this.startData)


				}, 300);
			},
		},
		tableList: {
			deep: true,
			immediate: true,
			handler: function (newV, oldV) {
				console.log('newV2222222', newV, this.tableListStartClone);
				// setTimeout(() => {
				// 	if (_.isEqual(newV, this.tableListStartClone)) {
				// 		this.$store.state.isStop.flg = false;
				// 		this.$store.state.isStop.next = 'default';
				// 	} else {
				// 		this.$store.state.isStop.flg = true;
				// 		this.$store.state.isStop.next = 'no';
				// 	}
				// }, 300);
				if (newV.length != this.tableListStartClone.length) {
					this.DataChange = true;
					return
				}
				newV.forEach((item, index) => {
					this.tableListStartClone[index]._XID = item._XID;
					Object.keys(item).forEach((key) => {
						console.log(this.tableListStartClone[index]);

						if (newV[index][key] == '') {
							this.tableListStartClone[index][key] = '';
						}
					})
				})
				this.DataChange = !_.isEqual(newV, this.tableListStartClone)
				console.log('newV2222222', newV, this.tableListStartClone);

			},
		},
		//clone初始值，监听变化，状态改为阻止=》当切换发现为阻止时，将名称改为’active'=》当发现名称修改时，跳出保存弹框
		//初始值设定，flg:false---name:default=>true---active
		//无论保存是否成功都要修改状态，然后可以跳转
		//偶发行情况，如果为添加时可以将初始值保存为空対象
		//1.当右菜单，无论弹出还是收回都初始值
		// this.$store.state.isStop.name = 'default';
		// this.$store.state.isStop.flg = false;
		//2.clone修改的数据
		//3.监听修改的数据=》修改状态、
		//4.监听状态=》是否跳出保存弹框=》无论保存是否成功都要修改状态，然后可以跳转
		//5.偶发行情况，如果为添加时可以将初始值保存为空対象
		// '$store.state.isStop.name': function (nVal, oVal) {
		// 	//你需要执行的代码
		// 	console.log(nVal, oVal);
		// 	if (nVal == 'active') {
		// 		this.saveRoEditor();
		// 	}
		// },
		// selectList: {
		// 	deep: true,
		// 	immediate: true,
		// 	handler: function (newV, oldV) {
		// 		console.log(_.isEqual(newV, this.startData));
		// 		if (_.isEqual(newV, this.startData)) {
		// 			this.$store.state.isStop.name = 'default';
		// 		} else {
		// 			this.$store.state.isStop.name = 'active';
		// 		}
		// 	},
		// },
	},
	methods: {

		async DelOperationApi() {
			this.delFlg = true;
			let msg = '工事計画[{選択した作業}]を削除します、宜しいですか？';
			msg = await this.GetSaveMsgApi(2);		//1=新增/修改 2=削除
			console.log(msg)
			this.$confirm(msg, ' ', {
				confirmButtonText: 'OK',
				cancelButtonText: 'Cancel',
				type: 'warning'
			}).then(async () => {
				let dataJson = {
					DmgCode: Number(this.$store.state.macCode),
					WrkClsCode: this.oldWCode,
					BaseYM: this.handRow.ctdMode == 1 ? '2023-01' : this.handRow.stdDate,
					Lvl: this.handRow.lvl.toString(),
				}
				let res = await DelOperation(dataJson);
				if (res.data.code != 0) {
					this.$alert(res.data.msg, '', {
						confirmButtonText: 'OK',
						type: 'warning',
						dangerouslyUseHTMLString: true,
					});
				}
				if (res.data.code == 0) {
					if (res.data.data.length != 0) {
						let str = res.data.data.join('<br />')
						this.$alert(str, ' ', {
							dangerouslyUseHTMLString: true,
							// type: 'warning',
							confirmButtonText: 'OK',
							type: 'warning',
						})
							.then(function () {

							})
							// .then(() => {

							// })
							.catch(() => { });
					} else {
						this.$message({
							type: 'success',
							message: res.data.msg
						})
					}
				}

				eventBus.$emit("refreshForMSC");
				this.GetOperationListApi({ dmgCode: Number(this.$store.state.macCode) });
				this.delFlg = false;
			}).catch(() => {
				this.delFlg = false;
			});
		},
		changType(tempIsAdd = false) {
			//初始监听状态
			if (!tempIsAdd) {
				eventBus.$emit('getBasicStyleCompontensCurrent_EventBus');	//	基本仕样
			}


			let Fn = () => {
				let qq = "ssqcop";
				this.handRow = {

					"cIspCts1": "",

					"cWrkCts1": "",

					"cWrkCts2": "",

					"cWrkCts3": "",

					"cstdJudge": "",

					"ctdMode": "0",

					"cyc": "",


					"iCodName": " ",


					"lCodName": " ",

					"lstSsnDate": "",

					"lvl": "",

					"nxtSsnDate": "",

					"stdDate": "",

					"wCodName": "",

					"wCodSymb": "",

					"wrkClsCode": ""

				}
				Object.keys(this.handRow).forEach(key => {
					if (key == 'stdDate') {
						var date = new Date();
						this.handRow[key] = `${date.getFullYear()}-${date.getMonth() + 1}`
						return
					}
					this.handRow[key] = ''
				})
				this.type = 1;
				this.handRow.wCodName = "";
				this.handRow.ctdMode = '0';
				// this.handRow.cyc = '';
				this.handRow.stdDate = `${new Date().getFullYear()}-${new Date().getMonth() + 1}`;
				this.stdJudgeCheck = true;
				this.tableList = [];
				// this.startData = _.cloneDeep(this.handRow);
			}
			/**
			 * 2。  记录当前函数。
			 */
			if (this.$store.state.isCurrentNext) {
				Fn();
			} else {
				/**
				  * 4-1。   记录原来该运行的函数。
				  * 4-2。   执行保存弹出框操作。   
				  */
				this.$store.commit("changeIsCurrentFn", Fn);

				eventBus.$emit('EventBusBasicStyleCompontensSaveFn');	//	基本仕样

			}


		},
		async saveRoEditor(isSaveBtn = false) {
			// if (this.isConfirming) {
			// 	return
			// }
			this.isConfirming = true;
			console.log('fsdfsdfsdfsdfsdfsdfsdf 111');

			if (this.handRow.ctdMode == 0 && !this.handRow.stdDate) {
				console.log('fsdfsdfsdfsdfsdfsdfsdf 222');
				let m = await this.getRequiredMsgByLabelApi('基準年月')
				this.$alert(m, '', {
					confirmButtonText: 'OK',
					type: 'warning',
					callback: action => {

					}
				});
				//  导航条误
				eventBus.$emit('isNavChangeErrorFn');
				//  搜索框索引误
				eventBus.$emit('backParamsForLeftView');
				return
			}
			//必填项
			let mastArr = ['開放分類', '優先度', '点検周期'];
			let dataArr = [this.handRow.wCodName, this.handRow.lvl, this.handRow.cyc];
			let mastMsg = '';
			for (let i = 0; i < mastArr.length; i++) {
				if (dataArr[i] === '') {
					mastMsg = await this.getRequiredMsgByLabelApi(mastArr[i])
				}
			}
			console.log(mastMsg)
			if (mastMsg != '') {
				console.log('fsdfsdfsdfsdfsdfsdfsdf 333');
				this.$alert(mastMsg, {
					confirmButtonText: 'OK',
					type: 'warning',
				});
				//  导航条误
				eventBus.$emit('isNavChangeErrorFn');
				//  搜索框索引误
				eventBus.$emit('backParamsForLeftView');
				return
			}
			//获取提示信息，执行操作
			console.log('编辑或保存', this.handRow);
			let msg = '変更内容を保存します、宜しいですか?';
			msg = await this.GetSaveMsgApi(1);		//1=新增/修改 2=削除
			console.log(msg)
			this.$confirm(msg, ' ', {
				confirmButtonText: 'OK',
				cancelButtonText: 'Cancel',
				type: 'warning'
			}).then(() => {
				this.startSave(isSaveBtn);
			}).catch(() => {
				// this.$store.commit('reSetIsStop');
				// eventBus.$emit('goNextOfLeftTable');
				// this.handleSelectionChange(this.startData)
				// if (isRefresh) {
				//     this.$store.state.isCurrentFn();
				//     this.$store.commit("reSetIsCurrent");
				//     return
				// }
				try {
					var tempFn = null;
					tempFn = this.$store.state.isCurrentFn.toString();
				} catch (error) {
					//
				}
				if (isSaveBtn) {
					return
				}
				this.$store.state.isCurrentNext = true;
				eventBus.$emit("refreshForMSC", false);
				this.GetOperationListApi({ dmgCode: Number(this.$store.state.macCode) });
				if (tempFn.indexOf('ssqcop') != -1) {
					setTimeout(() => {
						this.$store.state.isCurrentFn();
						this.$store.commit("reSetIsCurrent");
					}, 2000);
				} else {
					this.$store.state.isCurrentFn();
					this.$store.commit("reSetIsCurrent");
				}
			});
		},
		async startSave(isSaveBtn) {
			this.loading = true;

			let wCode = 0;
			this.selectList.wrkClsList.forEach((i, v) => {
				if (i.label == this.handRow.wCodName) {
					wCode = i.key
				}
			})
			let LCode = 0;
			this.selectList.clnClsList.forEach((i, v) => {
				if (i.label == this.handRow.lCodName) {
					LCode = i.key
				}
			})
			let ICode = 0;
			this.selectList.icdWrkList.forEach((i, v) => {
				if (i.label == this.handRow.iCodName) {
					ICode = i.key
				}
			})
			let UpdUser = localStorage.getItem('userName');
			let dataJson = {
				type: this.type,
				TabWrkClsCode: this.type == 1 ? 0 : this.oldWCode,
				DmgCode: Number(this.$store.state.macCode),
				PltCode: Number(this.$store.state.pltCode),
				SpecifiedValueCyc: Number(this.handRow.cyc),
				StdMode: Number(this.handRow.ctdMode) || 0,
				BaseYM: this.handRow.ctdMode == 1 ? '2023-01' : this.handRow.stdDate,
				WrkClsCode: Number(wCode),
				StdJudgeCheck: this.stdJudgeCheck ? 1 : 0,
				LCode,
				ICode,
				Lvl: this.handRow.lvl.toString(),
				UpdUser,
				IspCts1: this.handRow.cIspCts1,		//检査内容
				WrkCts1: this.handRow.cWrkCts1,		//工事内容
				WrkCts2: this.handRow.cWrkCts2,		//工事内容
				WrkCts3: this.handRow.cWrkCts3,		//工事内容
				// ExchangePartsList: this.tableList.filter(item => item.partsNo)
				ExchangePartsList: this.tableList
			}
			//执行前验证
			console.log(dataJson);

			let res = await AddOperationBefor(dataJson);
			if (res.data.code == 0) {
				this.$alert(res.data.data, {
					confirmButtonText: 'OK',
					type: 'warning',
				});
				this.loading = false;
				//  导航条误
				eventBus.$emit('isNavChangeErrorFn');
				//  搜索框索引误
				eventBus.$emit('backParamsForLeftView');
				return
			}

			console.log("执行前验证", res);

			let rr = await AddOperation(dataJson);
			this.loading = false;

			if (rr.data.code != 0) {
				let m = rr.data.msg.replace(/\r\n/g, '<br/>');
				this.$alert(m, {
					confirmButtonText: 'OK',
					type: 'warning',
					dangerouslyUseHTMLString: true,
				})
				//  导航条误
				eventBus.$emit('isNavChangeErrorFn');
				//  搜索框索引误
				eventBus.$emit('backParamsForLeftView');
				return
			}



			try {
				var tempFn = null;
				tempFn = this.$store.state.isCurrentFn.toString();
			} catch (error) {
				//
			}

			if (rr.data.code == 0) {
				if (rr.data.data.length != 0) {
					let str = rr.data.data.join('<br />')
					this.$alert(str, ' ', {
						dangerouslyUseHTMLString: true,
						confirmButtonText: 'OK',
						type: 'warning',
					})
				} else {
					this.$message({
						type: 'success',
						message: rr.data.msg
					})
				}
			}



			/**
			 * new
			 */
			//	刷新？
			this.$store.state.isCurrentNext = true;
			eventBus.$emit("refreshForMSC", false);
			this.GetOperationListApi({ dmgCode: Number(this.$store.state.macCode) });
			//	追加？
			if (tempFn.indexOf('ssqcop') != -1) {
				setTimeout(() => {
					this.handRow = {

						"cIspCts1": "",

						"cWrkCts1": "",

						"cWrkCts2": "",

						"cWrkCts3": "",

						"cstdJudge": "",

						"ctdMode": "0",

						"cyc": "",


						"iCodName": " ",


						"lCodName": " ",

						"lstSsnDate": "",

						"lvl": "",

						"nxtSsnDate": "",

						"stdDate": "",

						"wCodName": "",

						"wCodSymb": "",

						"wrkClsCode": ""

					}
					Object.keys(this.handRow).forEach(key => {
						if (key == 'stdDate') {
							var date = new Date();
							this.handRow[key] = `${date.getFullYear()}-${date.getMonth() + 1}`
							return
						}
						this.handRow[key] = ''
					})
					this.type = 1;
					this.handRow.wCodName = "";
					this.handRow.ctdMode = '0';
					// this.handRow.cyc = '';
					this.handRow.stdDate = `${new Date().getFullYear()}-${new Date().getMonth() + 1}`;
					this.stdJudgeCheck = true;
					this.tableList = [];
				}, 2000);
			}
			//	跳转？
			else if (!isSaveBtn) {
				this.$store.state.isCurrentFn()
				this.$store.commit("reSetIsCurrent");
			}
			return

			if (isSaveBtn) {

				eventBus.$emit("refreshForMSC", false);

				this.GetOperationListApi({ dmgCode: Number(this.$store.state.macCode) });
				return
			}
			if (tempFn.indexOf('ssqcop') != -1) {
				// eventBus.$emit("refreshForMSC", false);
			}
			setTimeout(() => {
				//	追加
				if (tempFn.indexOf('ssqcop') != -1) {
					this.$store.state.isCurrentNext = true;
					this.handRow = {

						"cIspCts1": "",

						"cWrkCts1": "",

						"cWrkCts2": "",

						"cWrkCts3": "",

						"cstdJudge": "",

						"ctdMode": "0",

						"cyc": "",


						"iCodName": " ",


						"lCodName": " ",

						"lstSsnDate": "",

						"lvl": "",

						"nxtSsnDate": "",

						"stdDate": "",

						"wCodName": "",

						"wCodSymb": "",

						"wrkClsCode": ""

					}
					Object.keys(this.handRow).forEach(key => {
						if (key == 'stdDate') {
							var date = new Date();
							this.handRow[key] = `${date.getFullYear()}-${date.getMonth() + 1}`
							return
						}
						this.handRow[key] = ''
					})
					this.type = 1;
					this.handRow.wCodName = "";
					this.handRow.ctdMode = '0';
					// this.handRow.cyc = '';
					this.handRow.stdDate = `${new Date().getFullYear()}-${new Date().getMonth() + 1}`;
					this.stdJudgeCheck = true;
					this.tableList = [];
					return
				}
				// this.getThckStyleApi();
				this.$store.state.isCurrentFn()

				this.$store.commit("reSetIsCurrent");

				setTimeout(() => {
					eventBus.$emit("refreshForMSC", false);
				}, 200);
			}, 2000);


			// setTimeout(() => {
			// 	// eventBus.$emit('reGetLeftList', this.$refs.tab1.basicStyleData.macNumb);
			// 	var tempFn = null;
			// 	if (isSaveBtn) {

			// 		eventBus.$emit("refreshForMSC", false);
			// 		// eventBus.$emit("LoadDetailTabelData");

			// 		this.GetOperationListApi({ dmgCode: Number(this.$store.state.macCode) });
			// 	} else {
			// 		this.$store.state.isCurrentFn()
			// 		tempFn = this.$store.state.isCurrentFn.toString();
			// 		this.$store.commit("reSetIsCurrent");
			// 		eventBus.$emit("refreshForMSC", false);
			// 		this.GetOperationListApi({ dmgCode: Number(this.$store.state.macCode) });
			// 	}

			// 	setTimeout(() => {
			// 		console.log('this.$store.state.isCurrentFn', tempFn.indexOf('ssqcop' != -1));

			// 		if (this.newAdd && tempFn.indexOf('ssqcop' != -1)) {
			// 			this.newAdd = false;
			// 			this.changType(true);
			// 		}
			// 	}, 500);
			// }, 500);

		},
		//获取编辑提示信息
		async GetSaveMsgApi(opeType) {
			let dataJson = {
				opeType,		//1=新增/修改 2=削除
				WrkClsName: this.handRow.wCodName
			}
			let res = await GetSaveMsg(dataJson);
			return res.data.data
		},
		//获取必填项提示
		async getRequiredMsgByLabelApi(Label) {
			let dataJson = {
				Label
			}
			let res = await getRequiredMsgByLabel(dataJson);
			return res.data.data
		},

		//获取下拉框
		getOfferComboxApi() {
			getOfferCombox().then((res) => {
				this.selectList = res.data.data;
				console.log(
					"SSSSSSSSSSSSSSSSSSSSSSSSSSS",
					res.data.data
				);
				this.GetOperationListApi({ dmgCode: Number(this.$store.state.macCode) });
			});
		},
		//获取信息
		GetOperationListApi(dataJson) {
			// let dataJson = {
			// 	dmgCode: this.selectRow.selectRow,
			// }
			this.allList = [];
			console.log(dataJson)
			GetOperationList(dataJson).then(res => {
				if (res.data.code == -310) {
					//如果没有数据将两个初始数据都clone为空
					// this.handRow = _.cloneDeep({ wCodName: '' });

					// this.changType();
					this.handRow = _.cloneDeep({});
					this.startData = _.cloneDeep({});
					this.handRow = {};
					this.noDataFlg = true;
					return
				}
				if (res.data.code != 0) {
					// this.changType();
					this.handRow = _.cloneDeep({});
					this.startData = _.cloneDeep({});

					this.noDataFlg = true;
					return
				}
				this.noDataFlg = false;
				this.allList = res.data.data;
				this.allList.forEach((i, v) => {
					i.id = v;
					console.log(i)
				})
				setTimeout(async () => {
					//有数据时默认选择第一行
					this.$refs.multipleTable.setCurrentRow(this.allList[0])
					this.handRow = _.cloneDeep(this.allList[0]);
					this.startData = _.cloneDeep(this.allList[0]);
					this.handleSelectionChange(this.allList[0], false)


					// 获取子list的数据
					await this.GetExchangePartsFn(this.allList[0]);

				}, 300);
				this.oldWCode = 0;
			})
		},
		async GetExchangePartsFn(row) {
			// let res = await GetExchangeParts({
			// 	dmgcode: 18910, lvl: 'A', wrkclscode: 7
			// });
			let res = await GetExchangeParts({
				dmgCode: Number(this.$store.state.macCode),
				Lvl: row.lvl,
				WrkClsCode: Number(row.wrkClsCode),
			});
			if (res.data.code != 0) {
				this.tableList = [];
				this.tableListStartClone = _.cloneDeep([]);
				return
			}
			this.tableList = res.data.data;
			setTimeout(() => {
				this.tableListStartClone = _.cloneDeep(this.tableList);
			}, 300);
			this.$refs.multipleTable1.setCurrentRow(this.tableList[0]);
			this.tableListRow = this.tableList[0];
			console.log('this.tableList', this.tableList);
		},
		//关闭有彩蛋
		onCloseClick() {
			// this.$store.commit("changeIsCurrentNext", true);
			// this.$store.commit("changeIsCurrentNext", true);
			this.$emit("onCloseClick", false);
		},
		//表格行
		async handleSelectionChange(e, isShowSaveFn = true) {

			//初始监听状态
			if (this.rightViewFlag1 && isShowSaveFn) {
				eventBus.$emit('getBasicStyleCompontensCurrent_EventBus');	//	基本仕样
			}

			let Fn = async () => {
				this.type = 2;
				console.log(e)
				this.stdJudgeCheck = e.cstdJudge == "基準年月も計画年月に含む" ? true : false;
				console.log(this.stdJudgeCheck, "sssssssss")
				tools.changeNull(e);
				this.handRow = _.cloneDeep(e);
				this.activeRowIndex = e.id;
				this.oldWCode = 0;
				this.selectList.wrkClsList.forEach((i, v) => {
					if (i.label == e.wCodName) {
						this.oldWCode = i.key
					}
				})
				//获取到数据克隆，等待如果切换比较后是否弹出保存弹框
				this.startData = _.cloneDeep(this.handRow);
				this.$refs.multipleTable.setCurrentRow(this.handRow);
				await this.GetExchangePartsFn(e);
			}
			/**
			 * 2。  记录当前函数。
			 */
			if (this.$store.state.isCurrentNext) {
				Fn();
			} else {
				/**
				  * 4-1。   记录原来该运行的函数。
				  * 4-2。   执行保存弹出框操作。   
				  */
				this.$refs.multipleTable.setCurrentRow(this.handRow);
				this.$store.commit("changeIsCurrentFn", Fn);

				eventBus.$emit('EventBusBasicStyleCompontensSaveFn');	//	基本仕样
			}




		},
		async handleSelectionChange1(e) {
			this.tableListRow = e;
		},
		addEditTableFn() {
			if (Object.keys(this.handRow).length == 0) {
				return
			}
			let partsNo = 1;
			try {
				partsNo = Number(this.tableList[this.tableList.length - 1].partsNo) + 1
			} catch (error) {

			}
			let temp = {
				"dmgCode": this.handRow.dmgCode,
				"lvl": this.handRow.lvl,
				"wrkClsCode": this.handRow.wrkClsCode,
				"partsNo": `${partsNo}`,
				"partsName": null,
				"partsBui": null,
				"partsSize": null,
				"partsVol": null,
				"partsStan": null,
				"partsMate": null,
				"partsNote": null
			}
			this.tableList.push(temp);
		},
		delEditTableFn() {
			this.tableList = this.tableList.filter(item => {
				console.log(item, this.tableListRow);
				return item != this.tableListRow
			});
			this.$refs.multipleTable1.setCurrentRow(this.tableList[0]);
			this.tableListRow = this.tableList[0];
		},
		dateChange(val) {
			console.log(`dateChange(${this.dateValue})`, val);
		},
	},
	created() {
	},
	mounted() {
		eventBus.$on("isGetInfo", () => {
			this.activeRowIndex = 0;
			this.GetOperationListApi({ dmgCode: Number(this.$store.state.macCode) });
			this.getOfferComboxApi();
		})


		if (BASE.IP == "http://192.168.33.200:8085") {
			this.timeFormat = "yyyy-MM";
		} else if (BASE.IP == "https://eng-dev-api.a-mis.com") {
			this.timeFormat = "MM-yyyy";
		} else if (BASE.IP == "https://demoapi.richtechcn.com") {
			this.timeFormat = "yyyy-MM";
		}

		//  监听通知，是否有数据变更
		eventBus.$on('getBasicStyleCompontensCurrent_EventBus', () => {
			//	无弹框，不处理
			if (!this.rightViewFlag1) {
				return
			}
			console.log('EventBusBasicStyleCompontensSaveFn 123');

			// 获取当前数据是否更改。
			this.$store.commit("changeIsCurrentNext", !this.DataChange);
		});

		//  接受通知唤起保存弹框
		eventBus.$on('EventBusBasicStyleCompontensSaveFn', () => {
			//	无弹框，不处理
			if (!this.rightViewFlag1) {
				return
			}
			if (!this.$store.state.isCurrentFn) {
				return
			}
			console.log('EventBusBasicStyleCompontensSaveFn 234');
			this.saveRoEditor();
		});

	},
	beforeDestroy() {
		eventBus.$off("isGetInfo");

		eventBus.$off('getBasicStyleCompontensCurrent_EventBus');
		eventBus.$off('EventBusBasicStyleCompontensSaveFn');
	},
	destroyed() { },
};
</script>
<style lang="scss" scoped>
.right-cps-view {
	width: 100%;
	height: calc(100% - 2px);
	padding: 16px 0;
	border: 1px solid #c3c3c3;
}

.tbs-view {
	padding: 0 10px;
	display: flex;

	button {
		width: 50% !important;
		height: 32px;
		text-align: center;
		line-height: 32px;
		// border: 1px solid #d3d3d3;
		border-radius: 0;
	}

	.el-button+.el-button {
		margin-left: 0px;
		width: 50%;
		// border-radius: 0 !important;
	}

	.active {
		// background: #106ebe;
		// color: #fff;
	}
}

.list {
	height: 185px;
	padding-bottom: 12px;
	margin-bottom: 12px;
	border: 1px solid #d3d3d3;
	overflow: hidden;

	::v-deep .elx-cell--title {
		margin: 0 auto;
	}

	.mark_whole {
		width: 15px;
		height: 15px;
		border-radius: 50%;
		background-color: red;
		margin: 0 auto;
	}

	.mark_half {
		width: 15px;
		height: 15px;
		border-radius: 50%;
		border: 2px solid black;
		margin: 0 auto;
	}

	.mark_shut {
		width: 15px;
		height: 3px;
		// border-radius: 50%;
		background-color: black;
		margin: 0 auto;
	}

	::v-deep .elx-cell--title .elx-checkbox--icon::before {
		display: none;
	}
}

.p-top12 {
	padding-top: 12px;
}

.row {
	width: 100%;
	display: flex;
	justify-content: flex-start;
	padding-bottom: 12px;
	align-items: center;

	.item {
		width: 48%;
		display: flex;
		justify-content: flex-start;

		.label {
			width: 89px;
			height: 32px;
			display: flex;
			align-items: center;
		}

	}

	.long-ipt {
		width: calc(100% - 89px);

		::v-deep .el-input__inner {
			width: 100%;
			height: 32px;
		}
	}

	.w130 {
		max-width: 130px;
		min-width: 130px;
		width: 130px;
	}
}

.alits {
	align-items: flex-start !important;
}

.ipt {
	width: 238px;
	height: 32px;

	::v-deep .el-input__inner {
		// width: 238px;
		height: 32px;
	}

	::v-deep .el-input__inner:focus {
		border: 1px solid #dcdfe6;
	}

	::v-deep .el-input__icon {
		line-height: 32px;
		color: #909399;
	}

	::v-deep .el-input__suffix {
		width: 32px;
		right: 0;
		background: #dee0e3;
	}
}

.orange {
	::v-deep .el-input__inner {
		background: #ffdeac;
	}
}



.container {
	width: 100%;
	height: calc(100% - 302px);
	overflow-y: scroll;
	padding: 12px 8px 28px 16px;


}


.textarea {
	::v-deep .el-textarea__inner {
		resize: none;
		// background: #ffffe1;
	}
}

.add-view {
	width: 100%;
	min-height: 49px;
	border-bottom: 1px solid #d9d9d9;
	display: flex;
	align-items: center;
	justify-content: flex-end;
	padding: 8px 10px 8px 0;

	button {
		width: 68px;
		height: 32px;
		// background: #ffffff;
		// 	border: 1px solid #d9d9d9;
		// 	margin-left: 12px;
		// 	border-radius: 4px;
	}
}

.add-view1 {
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0px 10px 0px 10px;

	button {
		width: 68px;
		height: 32px;
		// background: #ffffff;
		// 	border: 1px solid #d9d9d9;
		// 	margin-left: 12px;
		// 	border-radius: 4px;
	}
}

.footer-view {
	position: absolute;
	z-index: 10;
	bottom: 5px;
	width: calc(100% - 2px);
	height: 47px;
	padding: 0 15px;
	border-top: 1px solid #d9d9d9;
	display: flex;
	align-items: center;
	background: #ffffff;
	justify-content: space-between;

	button {
		min-width: 82px;
		height: 32px;
		// background: #ffffff;
		// border: 1px solid #d9d9d9;
		margin-right: 12px;
		border-radius: 4px;
	}

	button:nth-child(1) {
		// background: #106ebe;
		// color: #fff;
		padding: 0 15px;
		width: 130px !important;
		// border-radius: 0;
	}

	button:nth-child(2) {
		// position: absolute;
		// background: #eb7421;
		// color: #fff;
		right: 0px;
		line-height: 0;
	}
}

.center {
	text-align: center !important;
}

.w47 {
	width: 48px !important;
	min-width: 48px !important;

	::v-deep .el-input__inner {
		width: 100%;
		height: 32px;
		margin: 0 auto;
		padding: 0;
		text-align: center;
	}
}

.opa {
	opacity: .5;
}

.b700 {
	font-weight: 700;
}

.spb {
	justify-content: space-between !important;
}

.ii ::v-deep .el-input__suffix {
	display: none;
}

::v-deep .el-icon-date {
	// background-color: red;
	float: right;
	transform: translateX(120px);
}

::v-deep .el-date-editor .el-input__inner {
	padding-left: 15px !important;
}

::v-deep .editTable {
	.el-input__inner {
		background: none;
		border: 0 none;
		padding: 0;
		text-align: center;
	}

	.left .el-input__inner {
		text-align: left;
	}

	.right .el-input__inner {
		text-align: right;
	}
}

// ::v-deep .row--current {
// 	background-color: rgb(233, 236, 237) !important;
// }

.radio-view {
	width: 238px;
	height: 32px;
	border-radius: 4px;
	border: 1px solid #d9d9d9;
	display: flex;
	align-items: center;
	justify-content: center;
	padding-top: 3px;

	::v-deep .el-radio {
		width: 35%;
	}
}

.ipt1 {
	width: 155px;
	height: 32px;
	margin: 0 8px;

	::v-deep .el-input__inner {
		width: 155px;
		height: 32px;
	}

	::v-deep .el-input__inner:focus {
		border: 1px solid #dcdfe6;
	}

	::v-deep .el-input__icon {
		line-height: 32px;
		color: #909399;
	}
}

.mini-ipt74 {
	width: 94px;
	min-width: 94px;

	::v-deep .el-input__inner {
		width: 100%;
		height: 32px;
		text-align: right;
	}
}

.center {
	::v-deep .el-input__inner {
		text-align: center !important;
	}
}

.orange {
	::v-deep .el-input__inner {
		background: #ffdeac;
	}
}

::v-deep .elx-table--empty-placeholder {
	top: 20px !important;
}
</style>